export const filterNavByPermission = (navInfo, permissions, permissionNav) => {
  console.log('filterNavByPermission', navInfo, permissions)
  const allowedKeys = new Set()

  // 收集所有允许的key
  permissions.forEach((perm) => {
    if (permissionNav[perm]) {
      permissionNav[perm].forEach((key) => allowedKeys.add(key))
    }
  })

  return navInfo
    .map((item) => {
      if (!item.children || item.children.length === 0) {
        return allowedKeys.has(item.key) ? item : null
      }

      const filteredChildren = item.children.filter((child) => allowedKeys.has(child.key))
      if (filteredChildren.length === 0) return null

      return {
        ...item,
        children: filteredChildren,
      }
    })
    .filter((item) => item !== null)
}
